﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YArchitech.Revit;

namespace HYRElectric.Dimension
{
	public class DimensionUtil
	{
		public static List<Element> ElementTags(Document doc, Element element, BuiltInCategory category, List<string> tags)
		{
			if (doc == null || element == null)
			{
				return null;
			}
			List<Element> list = new List<Element>();
			foreach (Element element2 in new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(IndependentTag)).OfCategory(category).ToElements())
			{
				IndependentTag independentTag = element2 as IndependentTag;
				if (independentTag.TaggedLocalElementId == element.Id)
				{
					FamilySymbol familySymbol = doc.GetElementById(independentTag.GetTypeId()) as FamilySymbol;
					if (familySymbol != null)
					{
						if (tags.Count == 0)
						{
							list.Add(independentTag);
						}
						else
						{
							Parameter parameter = familySymbol.GetParameter("标记类别");
							if (parameter != null)
							{
								string item = parameter.AsString();
								if (tags.Contains(item))
								{
									list.Add(independentTag);
								}
							}
						}
					}
				}
			}
			return list;
		}

		public static void DeleteElementTags(Document doc, List<Element> tags)
		{
			foreach (Element element in tags)
			{
				doc.Delete(element.Id);
			}
			doc.Regenerate();
		}
	}
}
